package com.amumu.netctoss.entity;

import java.sql.Timestamp;
import java.util.Set;

public class Admin {
	private Integer id;
	private String code;
	private String password;
	private String name;
	private String telephone;
	private String email;
	private Timestamp enrollDate;
	private Set<Role> roles;
	//private int[] rid;
	private Set<Integer> rid;
	public Admin(){
		this.enrollDate = new Timestamp(System.currentTimeMillis());
	}
	
	public Set<Integer> getRid() {
		return rid;
	}

	public void setRid(Set<Integer> rid) {
		this.rid = rid;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

	public Timestamp getEnrollDate() {
		return enrollDate;
	}
	public void setEnrollDate(Timestamp enrollDate) {
		this.enrollDate = enrollDate;
	}

	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	public boolean hasRole(int id){
		for(Role r:roles){
			if(r.getId()==id)
				return true;
		}
		return false;
	}
	public String toRoleNames(){
		StringBuilder sb = new StringBuilder();
		for(Role r:roles){
			sb.append(r.getName());
			sb.append(",");
		}
		sb.deleteCharAt(sb.length()-1);
		return sb.toString();
	}
	
}
